//
// Created by mac on 2023/12/18.
//

// 删除链表中的节点
void DeleteNode(ListNode** head, ListNode* target)
{
    if(!head || !*head || !target) return;
    if(*head == target) //要删除的节点是头节点
    {
        *head = *head->next;
        delete target;
    }
    else if(!target->next)  //要删除的节点是尾节点
    {
        ListNode* prev = *head;
        while(prev->next != target) prev = prev->next;
        prev->next = target->next;
        delete target;
    }
    else  //要删除的节点是中间节点
    {
        ListNode* next = target->next;
        memcpy(target, next, sizeof(*next));
        delete next;
    }
}

